
/**
 * /**
 * 此例说明对原始类型Primitive赋值和对合成类型赋值是不一样的
 * 对原始类型赋值就直接拷贝值
 * 而对合成类型赋值拷贝的是对象的reference
 * 
 * 
 * 在这里我们只是探讨原始类型和非原始类型赋值时的不同
 * 实际上，直接操作对象的成员变量是有违oo原则的
 *
 * @author HikaruZhang
 *
 */
public class NotPrimitive
{    
    private Number n1 = null;
    
    private Number n2 = null;
    
    public NotPrimitive()
    {
        this.n1  = new Number();
        this.n2 = new Number();
    }
    
    public static void main(String[] args)
    {
        NotPrimitive np = new NotPrimitive();
        np.n1.i = 9;
        np.n2.i = 47;
        System.out.println("<<<<<<<<<<打印开始>>>>>>>>");
        System.out.println("n1.i:--->:" + np.n1.i);
        System.out.println("n2.i:--->:" + np.n2.i);
        System.out.println("-------------------------");
        np.n1 = np.n2;
        System.out.println("n1=n2-->n1.i:" + np.n1.i);
        System.out.println("n1=n2-->n2.i:" + np.n2.i);
        System.out.println("-------------------------");
        np.n1.i =  27;
        System.out.println("n1.i=27-->n1.i:" + np.n1.i);
        System.out.println("n1.i=27-->n2.i:" + np.n2.i);
        System.out.println("-------------------------");        
        np.aliasingTest(np.n1);
        System.out.println("aliasingTest-->n1.i:" + np.n1.i);
        System.out.println("aliasingTest-->n2.i:" + np.n2.i);
        System.out.println("<<<<<<<<<打印结束>>>>>>>>>");
    }
    
    public void aliasingTest(Number n)
    {
        n.i = 888888;
    }
}

class Number
{
    int i;
}